/*
Copyright (C) Ariff Ehsan, Abdul Hadi Fikri

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

/*  Author : Ariff Ehsan
 *  Date   : June 27, 2009
 */


#include <system.h>
#include <leds8/leds8.h>


void LEDS8_init(void) {
	/* initialize port as output */
	LEDS8_DDR = 0xff;
	
	/* set initial port value */
#ifdef LEDS8_ACTIVE_LOW
	LEDS8_PORT = 0xff;
#else
	LEDS8_PORT = 0;
#endif
}


inline void LEDS8_on(uint8_t pin) {
#ifdef LEDS8_ACTIVE_LOW
	CLR_BIT(LEDS8_PORT, pin);
#else
	SET_BIT(LEDS8_PORT, pin);
#endif
}


inline void LEDS8_off(uint8_t pin) {
#ifdef LEDS8_ACTIVE_LOW
	SET_BIT(LEDS8_PORT, pin);
#else
	CLR_BIT(LEDS8_PORT, pin);
#endif
}


inline void LEDS8_set(uint8_t value) {	
#ifdef LEDS8_ACTIVE_LOW
	LEDS8_PORT = ~value;
#else
	LEDS8_PORT = value;
#endif
}


inline void LEDS8_toggle(uint8_t pin) {
	FLIP_BIT(LEDS8_PORT, pin);
}

